/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-09-29 10:16:46
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-09-29 11:08:59
 * @FilePath: /react18-vite-admin/src/router/LazyComponent.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { type ReactNode, Suspense, lazy } from 'react';

import LoadingPage from '@/components/ui/LoadingPage/LoadingPage';

const MySuspense = (props: {
    children?: ReactNode;
    lazy?: () => Promise<{
        default: () => JSX.Element;
    }>;
}) => {
    const { children, lazy: lazyLoad } = props;
    const LazyComponent = lazyLoad ? lazy(lazyLoad) : undefined;

    return (
        <Suspense fallback={<LoadingPage style={{ height: 'auto' }} />}>
            {children}
            {LazyComponent && <LazyComponent />}
        </Suspense>
    );
};

export default MySuspense;
